package cn.iocoder.yudao.module.system.service.validation;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 数据完整性验证 Service 接口
 *
 * @author 芋道源码
 */
public interface DataIntegrityValidationService {

    /**
     * 验证考试数据的完整性
     *
     * @param examId 考试ID
     * @return 验证结果
     */
    ValidationResult validateExamDataIntegrity(Long examId);

    /**
     * 验证成绩数据的一致性
     *
     * @param examId 考试ID
     * @return 验证结果
     */
    ValidationResult validateScoreConsistency(Long examId);

    /**
     * 验证排名数据的正确性
     *
     * @param examId 考试ID
     * @return 验证结果
     */
    ValidationResult validateRankingCorrectness(Long examId);

    /**
     * 验证赋分数据的准确性
     *
     * @param examId 考试ID
     * @return 验证结果
     */
    ValidationResult validateAssignmentAccuracy(Long examId);

    /**
     * 验证选科组合数据的完整性
     *
     * @param examId 考试ID
     * @return 验证结果
     */
    ValidationResult validateSubjectCombinationIntegrity(Long examId);

    /**
     * 验证班级学生数据的一致性
     *
     * @param examId 考试ID
     * @return 验证结果
     */
    ValidationResult validateClassStudentConsistency(Long examId);

    /**
     * 执行全面的数据完整性检查
     *
     * @param examId 考试ID
     * @return 综合验证结果
     */
    ComprehensiveValidationResult performComprehensiveValidation(Long examId);

    /**
     * 生成数据质量报告
     *
     * @param examId 考试ID
     * @return 数据质量报告
     */
    DataQualityReport generateDataQualityReport(Long examId);

    /**
     * 修复数据不一致问题
     *
     * @param examId 考试ID
     * @param fixOptions 修复选项
     * @return 修复结果
     */
    DataFixResult fixDataInconsistencies(Long examId, DataFixOptions fixOptions);

    /**
     * 验证结果
     */
    class ValidationResult {
        private boolean valid;
        private String validationType;
        private List<String> errorMessages;
        private List<String> warningMessages;
        private Map<String, Object> statistics;
        private long validationTime;
        
        // 构造函数
        public ValidationResult() {}
        
        public ValidationResult(boolean valid, String validationType, 
                              List<String> errorMessages, List<String> warningMessages,
                              Map<String, Object> statistics) {
            this.valid = valid;
            this.validationType = validationType;
            this.errorMessages = errorMessages;
            this.warningMessages = warningMessages;
            this.statistics = statistics;
            this.validationTime = System.currentTimeMillis();
        }
        
        // Getters and Setters
        public boolean isValid() { return valid; }
        public void setValid(boolean valid) { this.valid = valid; }
        
        public String getValidationType() { return validationType; }
        public void setValidationType(String validationType) { this.validationType = validationType; }
        
        public List<String> getErrorMessages() { return errorMessages; }
        public void setErrorMessages(List<String> errorMessages) { this.errorMessages = errorMessages; }
        
        public List<String> getWarningMessages() { return warningMessages; }
        public void setWarningMessages(List<String> warningMessages) { this.warningMessages = warningMessages; }
        
        public Map<String, Object> getStatistics() { return statistics; }
        public void setStatistics(Map<String, Object> statistics) { this.statistics = statistics; }
        
        public long getValidationTime() { return validationTime; }
        public void setValidationTime(long validationTime) { this.validationTime = validationTime; }
    }

    /**
     * 综合验证结果
     */
    class ComprehensiveValidationResult {
        private boolean overallValid;
        private List<ValidationResult> detailResults;
        private ValidationSummary summary;
        private List<String> recommendations;
        private long totalValidationTime;
        
        // 构造函数
        public ComprehensiveValidationResult() {}
        
        public ComprehensiveValidationResult(boolean overallValid, List<ValidationResult> detailResults,
                                           ValidationSummary summary, List<String> recommendations) {
            this.overallValid = overallValid;
            this.detailResults = detailResults;
            this.summary = summary;
            this.recommendations = recommendations;
            this.totalValidationTime = System.currentTimeMillis();
        }
        
        // Getters and Setters
        public boolean isOverallValid() { return overallValid; }
        public void setOverallValid(boolean overallValid) { this.overallValid = overallValid; }
        
        public List<ValidationResult> getDetailResults() { return detailResults; }
        public void setDetailResults(List<ValidationResult> detailResults) { this.detailResults = detailResults; }
        
        public ValidationSummary getSummary() { return summary; }
        public void setSummary(ValidationSummary summary) { this.summary = summary; }
        
        public List<String> getRecommendations() { return recommendations; }
        public void setRecommendations(List<String> recommendations) { this.recommendations = recommendations; }
        
        public long getTotalValidationTime() { return totalValidationTime; }
        public void setTotalValidationTime(long totalValidationTime) { this.totalValidationTime = totalValidationTime; }
    }

    /**
     * 验证摘要
     */
    class ValidationSummary {
        private int totalChecks;
        private int passedChecks;
        private int failedChecks;
        private int warningChecks;
        private double successRate;
        
        // 构造函数
        public ValidationSummary() {}
        
        public ValidationSummary(int totalChecks, int passedChecks, int failedChecks, int warningChecks) {
            this.totalChecks = totalChecks;
            this.passedChecks = passedChecks;
            this.failedChecks = failedChecks;
            this.warningChecks = warningChecks;
            this.successRate = totalChecks > 0 ? (double) passedChecks / totalChecks * 100 : 0;
        }
        
        // Getters and Setters
        public int getTotalChecks() { return totalChecks; }
        public void setTotalChecks(int totalChecks) { this.totalChecks = totalChecks; }
        
        public int getPassedChecks() { return passedChecks; }
        public void setPassedChecks(int passedChecks) { this.passedChecks = passedChecks; }
        
        public int getFailedChecks() { return failedChecks; }
        public void setFailedChecks(int failedChecks) { this.failedChecks = failedChecks; }
        
        public int getWarningChecks() { return warningChecks; }
        public void setWarningChecks(int warningChecks) { this.warningChecks = warningChecks; }
        
        public double getSuccessRate() { return successRate; }
        public void setSuccessRate(double successRate) { this.successRate = successRate; }
    }

    /**
     * 数据质量报告
     */
    class DataQualityReport {
        private Long examId;
        private String examName;
        private int totalStudents;
        private int totalClasses;
        private Map<String, Integer> subjectCombinationCounts;
        private Map<String, QualityMetrics> qualityMetrics;
        private List<String> dataIssues;
        private List<String> qualityRecommendations;
        private long reportGenerationTime;
        
        // 构造函数
        public DataQualityReport() {}
        
        // Getters and Setters
        public Long getExamId() { return examId; }
        public void setExamId(Long examId) { this.examId = examId; }
        
        public String getExamName() { return examName; }
        public void setExamName(String examName) { this.examName = examName; }
        
        public int getTotalStudents() { return totalStudents; }
        public void setTotalStudents(int totalStudents) { this.totalStudents = totalStudents; }
        
        public int getTotalClasses() { return totalClasses; }
        public void setTotalClasses(int totalClasses) { this.totalClasses = totalClasses; }
        
        public Map<String, Integer> getSubjectCombinationCounts() { return subjectCombinationCounts; }
        public void setSubjectCombinationCounts(Map<String, Integer> subjectCombinationCounts) { this.subjectCombinationCounts = subjectCombinationCounts; }
        
        public Map<String, QualityMetrics> getQualityMetrics() { return qualityMetrics; }
        public void setQualityMetrics(Map<String, QualityMetrics> qualityMetrics) { this.qualityMetrics = qualityMetrics; }
        
        public List<String> getDataIssues() { return dataIssues; }
        public void setDataIssues(List<String> dataIssues) { this.dataIssues = dataIssues; }
        
        public List<String> getQualityRecommendations() { return qualityRecommendations; }
        public void setQualityRecommendations(List<String> qualityRecommendations) { this.qualityRecommendations = qualityRecommendations; }
        
        public long getReportGenerationTime() { return reportGenerationTime; }
        public void setReportGenerationTime(long reportGenerationTime) { this.reportGenerationTime = reportGenerationTime; }
    }

    /**
     * 质量指标
     */
    class QualityMetrics {
        private double completeness; // 完整性
        private double accuracy; // 准确性
        private double consistency; // 一致性
        private double validity; // 有效性
        private int totalRecords;
        private int validRecords;
        private int invalidRecords;
        
        // 构造函数
        public QualityMetrics() {}
        
        public QualityMetrics(double completeness, double accuracy, double consistency, 
                            double validity, int totalRecords, int validRecords, int invalidRecords) {
            this.completeness = completeness;
            this.accuracy = accuracy;
            this.consistency = consistency;
            this.validity = validity;
            this.totalRecords = totalRecords;
            this.validRecords = validRecords;
            this.invalidRecords = invalidRecords;
        }
        
        // Getters and Setters
        public double getCompleteness() { return completeness; }
        public void setCompleteness(double completeness) { this.completeness = completeness; }
        
        public double getAccuracy() { return accuracy; }
        public void setAccuracy(double accuracy) { this.accuracy = accuracy; }
        
        public double getConsistency() { return consistency; }
        public void setConsistency(double consistency) { this.consistency = consistency; }
        
        public double getValidity() { return validity; }
        public void setValidity(double validity) { this.validity = validity; }
        
        public int getTotalRecords() { return totalRecords; }
        public void setTotalRecords(int totalRecords) { this.totalRecords = totalRecords; }
        
        public int getValidRecords() { return validRecords; }
        public void setValidRecords(int validRecords) { this.validRecords = validRecords; }
        
        public int getInvalidRecords() { return invalidRecords; }
        public void setInvalidRecords(int invalidRecords) { this.invalidRecords = invalidRecords; }
    }

    /**
     * 数据修复选项
     */
    class DataFixOptions {
        private boolean fixRankingIssues;
        private boolean fixScoreConsistency;
        private boolean fixAssignmentErrors;
        private boolean fixMissingData;
        private boolean recalculateAll;
        
        // 构造函数
        public DataFixOptions() {}
        
        public DataFixOptions(boolean fixRankingIssues, boolean fixScoreConsistency, 
                            boolean fixAssignmentErrors, boolean fixMissingData, boolean recalculateAll) {
            this.fixRankingIssues = fixRankingIssues;
            this.fixScoreConsistency = fixScoreConsistency;
            this.fixAssignmentErrors = fixAssignmentErrors;
            this.fixMissingData = fixMissingData;
            this.recalculateAll = recalculateAll;
        }
        
        // Getters and Setters
        public boolean isFixRankingIssues() { return fixRankingIssues; }
        public void setFixRankingIssues(boolean fixRankingIssues) { this.fixRankingIssues = fixRankingIssues; }
        
        public boolean isFixScoreConsistency() { return fixScoreConsistency; }
        public void setFixScoreConsistency(boolean fixScoreConsistency) { this.fixScoreConsistency = fixScoreConsistency; }
        
        public boolean isFixAssignmentErrors() { return fixAssignmentErrors; }
        public void setFixAssignmentErrors(boolean fixAssignmentErrors) { this.fixAssignmentErrors = fixAssignmentErrors; }
        
        public boolean isFixMissingData() { return fixMissingData; }
        public void setFixMissingData(boolean fixMissingData) { this.fixMissingData = fixMissingData; }
        
        public boolean isRecalculateAll() { return recalculateAll; }
        public void setRecalculateAll(boolean recalculateAll) { this.recalculateAll = recalculateAll; }
    }

    /**
     * 数据修复结果
     */
    class DataFixResult {
        private boolean success;
        private int fixedIssues;
        private int remainingIssues;
        private List<String> fixedItems;
        private List<String> failedItems;
        private String fixSummary;
        private long fixDuration;
        
        // 构造函数
        public DataFixResult() {}
        
        public DataFixResult(boolean success, int fixedIssues, int remainingIssues,
                           List<String> fixedItems, List<String> failedItems, String fixSummary) {
            this.success = success;
            this.fixedIssues = fixedIssues;
            this.remainingIssues = remainingIssues;
            this.fixedItems = fixedItems;
            this.failedItems = failedItems;
            this.fixSummary = fixSummary;
            this.fixDuration = System.currentTimeMillis();
        }
        
        // Getters and Setters
        public boolean isSuccess() { return success; }
        public void setSuccess(boolean success) { this.success = success; }
        
        public int getFixedIssues() { return fixedIssues; }
        public void setFixedIssues(int fixedIssues) { this.fixedIssues = fixedIssues; }
        
        public int getRemainingIssues() { return remainingIssues; }
        public void setRemainingIssues(int remainingIssues) { this.remainingIssues = remainingIssues; }
        
        public List<String> getFixedItems() { return fixedItems; }
        public void setFixedItems(List<String> fixedItems) { this.fixedItems = fixedItems; }
        
        public List<String> getFailedItems() { return failedItems; }
        public void setFailedItems(List<String> failedItems) { this.failedItems = failedItems; }
        
        public String getFixSummary() { return fixSummary; }
        public void setFixSummary(String fixSummary) { this.fixSummary = fixSummary; }
        
        public long getFixDuration() { return fixDuration; }
        public void setFixDuration(long fixDuration) { this.fixDuration = fixDuration; }
    }

}